package edu.ptu.springboot04.controller;

import edu.ptu.springboot04.common.controller.AjaxResponse;
import edu.ptu.springboot04.common.controller.BaseController;
import edu.ptu.springboot04.domain.entity.Category;
import edu.ptu.springboot04.domain.vo.CategoryVo;
import edu.ptu.springboot04.mapping.CategoryMapping;
import edu.ptu.springboot04.service.ICategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @BelongsProject: springboot04
 * @BelongsPackage: edu.ptu.springboot04.controller
 * @Author: HYJ
 * @CreateTime: 2025-03-22  22:50
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/category")
public class CategoryController extends BaseController {
    @Resource
    private ICategoryService categoryService;

    // 类别列表
    @GetMapping("/list")
    public AjaxResponse list() {

        List<Category> categoryList = categoryService.list();

        List<CategoryVo> categoryVo = CategoryMapping.INSTANCE.toCategoryVo(categoryList);

        return categoryVo != null ? AjaxResponse.success(categoryVo) : AjaxResponse.failure("查询失败");
    }
}
